
<%@ page contentType="text/html;charset=UTF-8" %>
<%
	def sRemain= params.remain
%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="layout" content="main" />
    <title>产品售出</title>
  </head>
  <body>
    <div class="nav">
      <span class="menuButton"><g:link class="list" controller="importProduct" action="list">库存流水账列表</g:link></span>
    </div>
    <div class="body">
    

      <h1>产品售出流水账</h1>
      <g:if test="${flash.message}">
        <div class="message">${flash.message}</div>
      </g:if>
      <g:hasErrors bean="${productInstance}">
        <div class="errors">
          <g:renderErrors bean="${productInstance}" as="list" />
        </div>
      </g:hasErrors>
      <g:form name="sellDetailForm" action="sellSave" method="post" >
        <div class="dialog">
          <table>
            <tbody>
              <g:hiddenField name="remain" value="${params.remain}" />
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="number">进货单序号</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:productInstance,field:'number','errors')}">
                    <g:textField name="number" value="${params.id}" />
                </td>
              </tr>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="productName">产品名称:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:productInstance,field:'productName','errors')}">
                    <g:textField name="productName" value="${params.productName}" />
                </td>
              </tr>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="amount">数量:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:productInstance,field:'amount','errors')}">
                  <input type="text" id="amount" name="amount" value="${fieldValue(bean:productInstance,field:'amount')}"/>
                </td>
              </tr>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="inPrice">进价:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:productInstance,field:'inPrice','errors')}">
                  <input type="text" id="inPrice" name="inPrice" value="${fieldValue(bean:productInstance,field:'inPrice')}" />
                </td>
              </tr>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="modelNo">型号:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:productInstance,field:'modelNo','errors')}">
                  <input type="text" id="modelNo" name="modelNo" value="${fieldValue(bean:productInstance,field:'modelNo')}"/>
                </td>
              </tr>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="outPrice">销售价格:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:productInstance,field:'outPrice','errors')}">
                  <input type="text" id="outPrice" name="outPrice" value="${fieldValue(bean:productInstance,field:'outPrice')}" />
                </td>
              </tr>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="supplier">供应商:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:productInstance,field:'supplier','errors')}">
                  <g:select name="supplier.id" from="${Supplier.list()}" optionKey="id" value="${supplierId}" />
                </td>
              </tr>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="catalog">产品分类:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:productInstance,field:'catalog','errors')}">
                  <g:select name="catalog.id" from="${Catalog.list()}" optionKey="id" value="${catalogId}" />
                </td>
              </tr>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="inTime">进货时间:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:productInstance,field:'time','errors')}">
                  <g:datePicker name="time" value="${productInstance?.time}" precision="day"></g:datePicker>
                </td>
              </tr>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="sellTime">销售时间:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:productInstance,field:'sellTime','errors')}">
                  <g:datePicker name="sellTime" value="${productInstance?.sellTime}" precision="day"></g:datePicker>
                </td>
              </tr>
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="productFlag">货品情况:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:productInstance,field:'taskStatus','errors')}">
                  <g:select id="productFlag" name="productFlag" from="${['卖出']}" value="${productInstance.productFlag}" ></g:select>
                </td>
              </tr>

              <tr class="prop">
                  <td valign="top" class="name">
                      <label for="remarks">备注:</label>
                  </td>
                  <td valign="top" class="value ${hasErrors(bean:productInstance,field:'remarks','errors')}">
                      <g:textArea name="remarks" value="${fieldValue(bean:productInstance,field:'remarks')}"/>
                  </td>
              </tr>

            </tbody>
          </table>
        </div>
        
        <div class="buttons">
          <span class="button"><input class="save" type="button" value="Create" onclick="checkAmount();"/></span>
        </div>
      </g:form>
    </div>
        <g:javascript>
 function checkAmount() {
    var frm = document.sellDetailForm;
    var amount = frm.amount.value;
    var remain = <%=sRemain%>
    if (amount == null || amount == 0)
    {
          alert("抱歉!请重新售出输入该批货物数量")
          return false
    }
    if (amount > remain)
    {
       alert("抱歉，该批货物数量不够!请重新输入");
       return false
    }
    frm.submit()
}
</g:javascript>
  </body>
</html>
